package com.example.controller;

import com.example.pojo.*;
import com.example.service.TeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @GetMapping("/teacher/index/{username}")
    public Result getByUserName(@PathVariable String username) {
        Select select = teacherService.getByUserName(username);
        return Result.success(select);
    }

    @GetMapping("/teacher/zuoyes/{username}")
    public Result listHomeWork(@PathVariable String username) {
        List<HomeWork> homeWorkList = teacherService.listHomeWork(username);
        return Result.success(homeWorkList);
    }


    @PostMapping("/teacher/zuoye")
    public Result addHomeWork(@RequestBody HomeWork homeWork) {
        teacherService.addHomeWork(homeWork);
        return Result.success();
    }


    @GetMapping("/teacher/daka/{username}")
    public Result listTask(@PathVariable String username) {
        List<Task> taskList = teacherService.listTask(username);
        return Result.success(taskList);
    }


    @GetMapping("/teacher/main/{username}")
    public Result getByUserMsg(@PathVariable String username) {
        Teacher teacher = teacherService.getByUserMsg(username);
        return Result.success(teacher);
    }

    @GetMapping("teacher/getId/{username}")
    public Result getIdByUser(@PathVariable String username) {
        Integer id = teacherService.getIdByUser(username);
        return Result.success(id);
    }

    @GetMapping("/teacher/plan/{username}")
    public Result listplan(@PathVariable String username) {
        List<Plan> planList = teacherService.listplan(username);
        return Result.success(planList);
    }


    @PostMapping("/teacher/plan")
    public Result addPlan(@RequestBody Progress plan) {
        teacherService.addPlan(plan);
        return Result.success();
    }

    @PutMapping("/teacher/plandeta")
    public Result selectPlan(@RequestBody SelectDeta selectDeta) {
        Plan plan = teacherService.selectPlan(selectDeta);
        return Result.success(plan);
    }

    @PutMapping("/teacher/zouyedeta")
    public Result selectHomeWork(@RequestBody SelectDeta selectDeta) {
        log.info("查询作业的详细信息：{}", selectDeta.getId());
        HomeWork homeWork = teacherService.selectHomeWork(selectDeta);

        return Result.success(homeWork);
    }

    @PutMapping("/teacher/dakadeta")
    public Result selectTask(@RequestBody SelectDeta selectDeta) {
        log.info("查询作业的详细信息：{}", selectDeta.getId());
        Task task = teacherService.selectTask(selectDeta);

        return Result.success(task);
    }

    @PostMapping("/teacher/daka")
    public Result addTask(@RequestBody Task task) {
        teacherService.addTask(task);
        return Result.success();
    }


    @GetMapping("/teacher/announ/{username}")
    public Result getAnnoun(@PathVariable String username) {
        List<Announcemen> announcemenList = teacherService.getAnnoun(username);
        return Result.success(announcemenList);

    }

    @GetMapping("/teacher/progress/{username}")
    public Result listProgress(@PathVariable String username) {
        List<Progress> progressList = teacherService.listProgress(username);
        return Result.success(progressList);
    }


    @PostMapping("/teacher/progress")
    public Result addProgress(@RequestBody Progress progress) {
        teacherService.addProgress(progress);
        return Result.success();
    }

    @PostMapping("/teacher/setpass")
    public Result setPassWord(@RequestBody Pass pass) {
        teacherService.setPassWord(pass);
        return Result.success();
    }

    @GetMapping("/teacher/opinion/{username}")
    public Result getOpinion(@PathVariable String username) {
        List<Opinion> opinionList = teacherService.listOpinion(username);
        return Result.success(opinionList);
    }

    @GetMapping("/teacher/introduction")
    public Result getIntroduction() {
        List<Teacher> teacherList = teacherService.listTeacher();
        return Result.success(teacherList);
    }


    @GetMapping("/teacher/student/{username}")
    public Result getStudent(@PathVariable String username) {
        List<Student> studentList = teacherService.listStudent(username);
        return Result.success(studentList);
    }

    @PostMapping("/teacher/money")
    public Result addMoney(@RequestBody ClassFee classFee) {
        teacherService.addClassFee(classFee);
        return Result.success();
    }

    @GetMapping("/teacher/renjiao/{username}")
    public Result getTeacherByClass(@PathVariable String username){
        List<Teacher> teacherList = teacherService.getTeacherByClass(username);
        return Result.success(teacherList);
    }
}
